package com.mf.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mf.entity.dto.RosterDto;
import com.mf.entity.dto.roster.RosterChangeJobDto;
import com.mf.entity.dto.roster.RosterChangeTypeDto;
import com.mf.entity.dto.roster.RosterLeaveDto;
import com.mf.entity.request.roster.RosterRequest;
import com.mf.entity.vo.RosterVo;
import com.mf.service.IDeptService;
import com.mf.service.IRosterService;
import io.github.heollhai.common.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;


/**
 * @author mf
 * @since 2024-09-01
 */
@RestController
@RequestMapping("personnel/roster/v1")
@Tag(name = "花名册")
public class RosterController {
    @Resource
    private IRosterService rosterService;

    @Resource
    private IDeptService deptService;

    @Operation(summary = "新增|编辑")
    @PostMapping("save")
    public Result<Integer> save(@Valid @RequestBody RosterDto rosterDto) {
        return Result.success(rosterService.insert(rosterDto));
    }

    @Operation(summary = "删除")
    @GetMapping("delete/{id}")
    public Result<Integer> deleteById(@PathVariable("id") Integer id) {
        return Result.success(rosterService.deleteById(id));
    }

    @Operation(summary = "分页查询")
    @PostMapping("PageList")
    public Result<Page<RosterVo>> PageList(@Valid @RequestBody RosterRequest rosterRequest) {
        Page<RosterVo> rosterVoPage = rosterService.PageList(rosterRequest);

        return Result.success(deptService.setDeptAndJob(rosterVoPage));
    }

    @Operation(summary = "提交")
    @GetMapping("submit/{id}")
    public Result<Integer> submit(@PathVariable("id") Integer id) {
        return Result.success(rosterService.submit(id));
    }

    @Operation(summary = "修改员工类型")
    @PostMapping("changeType")
    public Result<Integer> changeType(@Valid @RequestBody RosterChangeTypeDto rosterChangeTypeDto) {
        return Result.success(rosterService.changeType(rosterChangeTypeDto));
    }

    @Operation(summary = "离职")
    @PostMapping("leave")
    public Result<Integer> leave(@Valid @RequestBody RosterLeaveDto rosterLeaveDto) {
        return Result.success(rosterService.leave(rosterLeaveDto));
    }

    @Operation(summary = "修改员工岗位")
    @PostMapping("changeJob")
    public Result<Integer> changeJob(@Valid @RequestBody RosterChangeJobDto rosterChangeJobDto) {
        return Result.success(rosterService.changeJob(rosterChangeJobDto));
    }
}
